﻿namespace Micro.Extensions.Utilities
{
    public class ComResult
    {
        public ComResult()
        {
        }
        /// <summary>
        /// 响应码
        /// </summary>
        public int Code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 业务成功
        /// </summary>
        public static ComResult<T> Success<T>(T data, AttachPage pager = null,int code = 200,string msg = "成功")
        {
            return new ComResult<T>
            {
                ReturnObj = data,
                Pager = pager,
                Msg = msg,
                Code = code
            };
        }

        /// <summary>
        /// 成功
        /// </summary>
        public static ComResult Success(int code =200,string msg = "成功")
        {
            return new ComResult
            {
                Msg = msg,
                Code = code
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        public static ComResult<T> Failed<T>(int code, string msg = "失败")
        {
            return new ComResult<T>
            {
                Code = code,
                Msg = msg
            };
        }


        /// <summary>
        /// 失败
        /// </summary>
        public static ComResult Failed(int code, string msg = "失败")
        {
            return new ComResult
            {
                Code = code,
                Msg = msg
            };
        }


    }
    /// <summary>
    /// 通用业务返回泛型类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ComResult<T> : ComResult
    {
        public ComResult()
        {
        }

        /// <summary>
        /// 返回结果
        /// </summary>
        public T ReturnObj { get; set; }

        /// <summary>
        /// 分页信息类
        /// </summary>
        public AttachPage Pager { get; set; }

    }

}
